<template>
	<view class="content">
		<view class="wash-shoes-list">
			<view class="wash-shoes-li" v-for="(item,index) in shoeList" :key="index">
				<image :src="'https://www.sdxiecheng.cn/'+item.image" mode=""></image>
				<view class="wash-shoes-list-r">
					<view class="title">{{ item.name }}</view>
					<view class="des u-line-2">
						{{ item.describle }}
					</view>
					<view class="price">
						<view>{{ item.price }}元/{{ item.unit }} <text
								v-if="item.member_price">会员价：{{ item.member_price }}元</text></view>
						<view class="price-caozuo">
							<image @click="addCard(item.id, item.is_new_user, item.is_new)" src="https://www.sdxiecheng.cn/img/catAdd.png" mode="">
							</image>
							<button class="u-reset-button" @click="xiadan(item.id, item.is_new_user, item.is_new)">立即下单</button>
						</view>
					</view>
				</view>
			</view>
		</view>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import {
		mapMutations,
		mapActions,
		mapState,
		mapGetters
	} from 'vuex';
	export default {
		data() {
			return {
				page: 1,
				last_page: 1,
				shoeList: []
			}
		},
		onLoad() {
			// this.getShoeList()
		},
		onShow() {
			this.shoeList = []
			this.getShoeList()
		},
		onReachBottom() {
			console.log(this.page)
			if (this.page < this.last_page) {
				this.page += 1;
				this.getShoeList();
			}
		},
		methods: {
			...mapActions(['addCartGoods', 'getCartList']),
			xiadan(id, is_new_user, is_new) {
				if (is_new == 1 && is_new_user == 0) {
					this.$refs.uToast.show({
						title: '您不属于新用户'
					})
					return
				}
				uni.navigateTo({
					url: '../order/place_order/place_order?id=' + id
				})
			},
			addCard(id, is_new_user, is_new) {
				// uni.showToast({
				// 	icon:'success',
				// 	title:'加入购物车成功'
				// })
				if (is_new == 1 && is_new_user == 0) {
					this.$refs.uToast.show({
						title: '您不属于新用户'
					})
					return
				}
				let confirmGoodsList = {
					id: id,
					quantity: 1
				}
				this.addCartGoods(confirmGoodsList).then(res => {
					console.log(res)
					if (res.code == 200) {
						uni.showToast({
							icon: 'success',
							title: res.msg
						})
					}
				})
			},
			// 获取洗鞋列表
			getShoeList() {
				uni.$u.http.post('/shoe/shoe_list', {
					shoecabinet_id: this.$store.state.shoecabinet_id,
					page: this.page
				}).then(res => {
					this.shoeList = [...this.shoeList, ...res.data.data]
					this.last_page = res.data.last_page
					this.page = res.data.current_page
				}).catch(err => {
					
				})
			}
		}
	}
</script>

<style lang="less">
	.content {
		padding: 20rpx;
	}

	.wash-shoes-list {
		height: 100vh;

		// margin-top: 40rpx;
		.wash-shoes-li {
			width: 100%;
			height: 220rpx;
			background: #FFFFFF;
			margin-bottom: 30rpx;
			border-radius: 10rpx;
			overflow: hidden;
			display: flex;
			align-items: center;
			padding: 30rpx 20rpx;

			image {
				width: 160rpx;
				height: 160rpx;
				border-radius: 10rpx;
				overflow: hidden;
			}

			.wash-shoes-list-r {
				width: calc(100% - 160rpx);
				padding-left: 21rpx;

				.title {
					font-size: 30rpx;
					font-weight: bold;
					margin-bottom: 13rpx;
				}

				.des {
					font-size: 24rpx;
					color: #7C7C7C;
					line-height: 30rpx;
					margin-bottom: 10rpx;
				}

				.price {
					display: flex;
					align-items: center;
					justify-content: space-between;

					view {
						font-size: 24rpx;
						color: #333333;

						text {
							color: #FBAA27;
							margin-left: 13rpx;
						}
					}

					.price-caozuo {
						display: flex;
						align-items: center;

						image {
							width: 30rpx;
							height: 30rpx;
							margin-right: 17rpx;
						}

						button {
							color: #FBAA27;
							font-size: 24rpc;
							font-weight: bold;
							border: 2rpx solid #FBAA27;
							padding: 0 12rpx;
							line-height: 42rpx;
							border-radius: 21px;
						}
					}
				}
			}
		}
	}
</style>
